package nl.hro.mobiqueen.ui;

import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import nl.hro.mobiqueen.R;
import nl.hro.mobiqueen.data.DatabaseAdapter;
import nl.hro.mobiqueen.data.objects.Event;

public class OptredenDetail extends MobiBase {

    public boolean IsChecked = false;

    private DatabaseAdapter DA;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Toast.makeText(this, "Event Id: " + getIntent().getIntExtra("eventId", -1), Toast.LENGTH_LONG).show();

        setContentView(R.layout.detailperformance);
        DA = new DatabaseAdapter(this);
        DA.open();

        Event event = DatabaseAdapter.getEventFromCursor(DA.findEvent(getIntent().getIntExtra("eventId", -1)));
        Cursor c =  DA.findArtist(event.getArtist());
        Cursor d = DA.findFavoriteById(event.getArtist());
        ImageView HeaderImg = (ImageView)findViewById(R.id.header);
        ImageView ArtitsImg = (ImageView)findViewById(R.id.Artist_image);
        ImageView StarImg = (ImageView)findViewById(R.id.favorites_image);

        Button Tbutton = (Button) findViewById(R.id.togglebutton);
        TextView txtDescription = (TextView)findViewById(R.id.txtDescription);
        TextView txtName = (TextView)findViewById(R.id.txtName);

        int artistID = event.getId();
        int Temp_ID;

        switch (artistID) {
            case 1:  Temp_ID = R.drawable.arminbuuren;       break;
            case 2:  Temp_ID = R.drawable.alib;      break;
            case 3:  Temp_ID = R.drawable.anouk;      break;
            case 4:  Temp_ID = R.drawable.arcadefire;      break;
            case 5:  Temp_ID = R.drawable.avril;      break;
            case 6:  Temp_ID = R.drawable.blof;       break;
            case 7:  Temp_ID = R.drawable.brainpower;      break;
            case 8:  Temp_ID = R.drawable.dedijk;      break;
            case 9:  Temp_ID = R.drawable.direct;      break;
            case 10: Temp_ID = R.drawable.esmeedenters;      break;
            case 11: Temp_ID = R.drawable.extince;       break;
            case 12:  Temp_ID = R.drawable.girlsaround;      break;
            case 13:  Temp_ID = R.drawable.guusmeeuwis;      break;
            case 14:  Temp_ID = R.drawable.isis;      break;
            case 15:  Temp_ID = R.drawable.junkiexl;      break;
            case 16:  Temp_ID = R.drawable.kane;       break;
            case 17:  Temp_ID = R.drawable.ladygaga;      break;
            case 18:  Temp_ID = R.drawable.limpbizkit;      break;
            case 19:  Temp_ID = R.drawable.nicksimon;      break;
            case 20:  Temp_ID = R.drawable.petephilly;      break;
            case 21:  Temp_ID = R.drawable.tiesto;      break;
            case 22:  Temp_ID = R.drawable.wizkhalifa;       break;
            case 23:  Temp_ID = R.drawable.xander;      break;
            default: Temp_ID = R.drawable.blof; break;
        }

        ArtitsImg.setImageResource(Temp_ID);

        String name = c.getString(c.getColumnIndex(DatabaseAdapter.KEY_NAME));
        String description = c.getString(c.getColumnIndex(DatabaseAdapter.KEY_DESCRIPTION));
        txtDescription.setText(description);
        txtName.setText(name);

        if(d.getColumnIndex(DatabaseAdapter.KEY_FAVORITE) == -1 || d.getColumnIndex(DatabaseAdapter.KEY_FAVORITE) == 0 )
        {
           IsChecked = false;
            Tbutton.setText("SetFavorites");
            StarImg.setVisibility(View.INVISIBLE);
        }else
        {
           IsChecked = true;
           Tbutton.setText("IsFavorites");
            StarImg.setVisibility(View.VISIBLE);
            StarImg.bringToFront();
        }

        if(event.getGenre().equals(""))
        {

        }else
        {

            EGenre.Genre myGenre = EGenre.StringToEGenre(event.getGenre());

            int temp_Genre;
            switch (myGenre) {
                case DANCE: temp_Genre = R.drawable.detailtitlebackgroundpurple;       break;
                case POP: temp_Genre = R.drawable.detailtitlebackgroundblue;       break;
                case NEDERLANDS: temp_Genre = R.drawable.detailtitlebackgroundorange;       break;
                case ROCK: temp_Genre = R.drawable.detailtitlebackgroundred;       break;
                case HIPHOP: temp_Genre = R.drawable.detailtitlebackgroundyellow;       break;
                default: temp_Genre = R.drawable.detailtitlebackgroundpurple; break;
            }

           HeaderImg.setImageResource(temp_Genre);

        }

    }



    


    public void toggleClick(View button)
    {

        TextView txtName = (TextView)findViewById(R.id.txtName);
        Button Tbutton = (Button) findViewById(R.id.togglebutton);
        ImageView FavoritesImg = (ImageView)findViewById(R.id.favorites_image);
        if (IsChecked) {
           IsChecked = false;
           Tbutton.setText("SetFavorites");
           FavoritesImg.setVisibility(View.INVISIBLE);
           DA.toggleFavorite((String) txtName.getText());
        } else {
           IsChecked = true;
           Tbutton.setText("IsFavorites");
           FavoritesImg.setVisibility(View.VISIBLE);
           DA.toggleFavorite((String) txtName.getText());
        }

    }

    public void ProgramClick(View button)
    {
        Intent intent = new Intent(button.getContext(),
                        Plattegrond.class);
        startActivity(intent);

    }

    public void GoogleNavigateClick(View button)
    {
        Intent intent = new Intent(button.getContext(),
                        Plattegrond.class);
        startActivity(intent);

    }

}
